<template>
  <div>
    <el-menu default-active="1-4-1" class="el-menu-vertical-demo" :collapse="isCollapse" background-color="#545c65"
      text-color="white" active-text-color="#409eff" router>
      <h3>{{ isCollapse ? "后台" : "权限管理后台" }}</h3>
      <el-menu-item
      v-for="item in noChildren"
      :index="item.path"
      :key="item.path"
    >
      <i :class="`el-icon-${item.children[0].meta.icon}`"></i>
      <span slot="title">{{ item.children[0].meta.title }}</span>
    </el-menu-item>

    <el-submenu v-for="item in hasChildren" :index="item.path" :key="item.path">
      <template slot="title">
        <i :class="`el-icon-${item.meta.icon}`"></i>
        <span slot="title">{{ item.meta.title }}</span>
      </template>
      <el-menu-item-group v-for="subItem in item.children" :key="subItem.path">
        <el-menu-item :index="subItem.path">
          <i :class="`el-icon-${subItem.meta.icon}`"></i>
          {{ subItem.meta.title }}
        </el-menu-item>
      </el-menu-item-group>
    </el-submenu>
    </el-menu>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  computed: {
    ...mapGetters(["adminRoutes"]),
    noChildren() {
     
      return this.adminRoutes.filter((item) => item.children.length < 2);
    },
    hasChildren() {
      return this.adminRoutes.filter((item) => item.children.length >= 2);
    },
    isCollapse() {
      return this.$store.state.tabs.isCollapse;
    },
  },
};
</script>

<style lang="less" scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}

.el-menu {
  height: 100vh;
  border: 0;

  h3 {
    // background-color: #545c65;
    color: #fff;
    text-align: center;
    line-height: 48px;
    font-size: 16px;
  }
}
</style>